﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace GenerateAccessors
{
	internal static class Extensions
	{
		public static bool HasByRefParameters(this MethodInfo info)
		{
			return info.GetParameters().Any(p => p.ParameterType.IsByRef);
		}

		public static bool IsPropertyAccessor(this MethodInfo info, PropertyInfo[] properties)
		{
			return properties.Any(p => p.GetAccessors(true).Contains(info));
		}

		public static bool IsEntirelyPublic(this Type type)
		{
			if (type.IsGenericType)
			{
				foreach (Type argument in type.GetGenericArguments())
				{
					if (!argument.IsEntirelyPublic())
						return false;
				}
			}

			if (type.IsNested)
			{
				return type.IsNestedPublic && type.DeclaringType.IsEntirelyPublic();
			}

			if (type.IsArray)
			{
				return type.GetElementType().IsEntirelyPublic();
			}

			return type.IsPublic;
		}
	}
}
